This repository was archived by the owner on Jun 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 250
Fixed support for Django 4.1 #1159
Merged
lzchen
merged 3 commits into
census-instrumentation:master
from
JeremyVriens:tasks/fixed_support_for_django_4.1
Aug 26, 2022
Merged
Fixed support for Django 4.1 #1159
lzchen
merged 3 commits into
census-instrumentation:master
from
JeremyVriens:tasks/fixed_support_for_django_4.1
Aug 26, 2022
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lzchen
approved these changes
Aug 25, 2022
@JeremyVriens |
When used correctly as described in the README, it should not be as Django passes the request through all the registered middlewares (see also their documentation: https://docs.djangoproject.com/en/4.1/topics/http/middleware/). The default value of None for the get_response argument was in that sense never correct. |
When a release will be available for this fix? |
If anyone is still waiting for this fix to be released, here is a snippet you can use to patch the middleware for now: # myapp/settings.py
MIDDLEWARE = [
# 'opencensus.ext.django.middleware.OpencensusMiddleware',
'myapp.middleware.PatchedOpencensusMiddleware',
] # myapp/middleware.py
import django
from opencensus.ext.django.middleware import (
OpencensusMiddleware,
EXCLUDELIST_PATHS,
EXCLUDELIST_HOSTNAMES,
_trace_db_call
)
import six
from django.db import connection
from opencensus.common import configuration
from opencensus.trace import (
integrations,
print_exporter,
samplers,
)
from opencensus.trace.propagation import trace_context_http_header_format
class PatchedOpencensusMiddleware(OpencensusMiddleware):
def __init__(self, get_response=None):
super(OpencensusMiddleware, self).__init__(get_response)
settings = getattr(django.conf.settings, 'OPENCENSUS', {})
settings = settings.get('TRACE', {})
self.sampler = (settings.get('SAMPLER', None)
or samplers.ProbabilitySampler())
if isinstance(self.sampler, six.string_types):
self.sampler = configuration.load(self.sampler)
self.exporter = settings.get('EXPORTER', None) or \
print_exporter.PrintExporter()
if isinstance(self.exporter, six.string_types):
self.exporter = configuration.load(self.exporter)
self.propagator = settings.get('PROPAGATOR', None) or \
trace_context_http_header_format.TraceContextPropagator()
if isinstance(self.propagator, six.string_types):
self.propagator = configuration.load(self.propagator)
self.excludelist_paths = settings.get(EXCLUDELIST_PATHS, None)
self.excludelist_hostnames = settings.get(EXCLUDELIST_HOSTNAMES, None)
if django.VERSION >= (2,): # pragma: NO COVER
connection.execute_wrappers.append(_trace_db_call)
# pylint: disable=protected-access
integrations.add_integration(integrations._Integrations.DJANGO) |
Thanks @lzchen, not the first time you've helped me out. Super appreciated |
inirudebwoy
pushed a commit
to inirudebwoy/opencensus-python
that referenced
this pull request
Jan 11, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the support for Django 4.1 according to this bug report: #1154
The issue was a missing call to init of the super class, which worked fine before, but broke as of this change in Django: django/django#15216